# import the necessary packages
import cv2 as cv
import numpy as np
import argparse

# construct the argument parser and parse the argument
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="The Path to Image")
args = vars(ap.parse_args())

# load the image and show it
image = cv.imread(args["image"])
cv.imshow("Original", image)

# images are Numpy arrays,stored as unsigned 8 gbit integers -- this
# implies that the valeus of our pixels will bi in the range [0,255];when
# using functions like cv2.add and cv2.substract,valeus will be clipped
# to this range,even if the added or substracted valeus fall outside the
# range of [0,255]. Check out an example:
print("max of 255: {}".format(str(cv.add(np.uint8([200]), np.uint8([100])))))
print("min of 0: {}".format(str(cv.add(np.uint8([50]), np.uint8([100])))))

# NOTE: if you are use Numpy arithmetic operations on these arrays,the value
# will be modulo (warp around) instead of being clipped to the [0,255]
# range.This is important to keep in mind whn working with images
print("warp around: {}".format(str(np.uint8([200]) + np.uint8([100]))))
print("warp around: {}".format(str(np.uint8([50]) - np.uint8([100]))))
print("300 % 256 = {}".format(300 % 256))
print("-50 % 256 = {}".format(-50 % 256))

# let's increase the intensity of all pixels in our image by 100 -- we
# accomplish this by constructing a Numpy array that is the same size of
# our matrix (filled with ones) and the multiplying it by 100 to create an
# array filled with 100's,then we simply add the images together; notice
# how the image is "brighter"
M = np.ones(image.shape,dtype="uint8") * 100
added = cv.add(image,M)
cv.imshow("Added",added)

#similarly,we can substract 50 from all pixels in our iamge and make it
#darker
M = np.ones(image.shape,dtype="uint8") * 50
substracted  = cv.subtract(image,M)
cv.imshow("Substracted",substracted)
cv.waitKey(0)
